//
//  ViewController.m
//  TestDemo
//
//  Created by 小菜 on 16/6/17.
//  Copyright © 2016年 蔡凌云. All rights reserved.
//

#import "ViewController.h"
#import "Person.h"
#import "TwoViewController.h"

@interface ViewController ()<UITextViewDelegate>

@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) NSArray<Person *> *datas;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"页面一";
    
    self.view.backgroundColor = [UIColor orangeColor];
    _textView = [[UITextView alloc] init];
    _textView.frame= FRAME(0, 0, 200, 38);
    _textView.center = self.view.center;
    _textView.delegate = self;
    _textView.font = [UIFont systemFontOfSize:38];
    [self.view addSubview:_textView];
    
//    Smith John 03/01/1984
//    Andersen Jane 16/03/1979
//    Clark Anne 13/09/1995
//    Smith David 19/07/1981
//    Johnson Rose 22/02/1989
    
    Person *p1 = [[Person alloc] init];
    p1.name = @"Smith";
    p1.surname = @"John";
    p1.index = 3;
    
    Person *p2 = [[Person alloc] init];
    p2.name = @"Andersen";
    p2.surname = @"Jane";
    p2.index = 2;
    self.datas = @[p1,p2];
//    
//    NSArray *sortedArr = [self.datas sortedArrayUsingComparator:^NSComparisonResult(Person  *_Nonnull obj1, Person  *_Nonnull obj2) {
//        
//        return [obj1.index compare:obj2.index];
//    }];
    
//    for (int i = 0; i < sortedArr.count; i++) {
//        Person *p = sortedArr[i];
//        LxDBAnyVar(p.surname);
//    }
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    LxDBAnyVar(@"11");
    [self.navigationController pushViewController:[TwoViewController new] animated:YES];
}
NSInteger customSort(id obj1, id obj2,void* context){
    if ([obj1 integerValue] > [obj2 integerValue]) {
        return (NSComparisonResult)NSOrderedDescending;
    }
    
    if ([obj1 integerValue] < [obj2 integerValue]) {
        return (NSComparisonResult)NSOrderedAscending;
    }
    return (NSComparisonResult)NSOrderedSame;
}
NSComparator cmptr = ^(id obj1, id obj2){
    if ([obj1 integerValue] > [obj2 integerValue]) {
        return (NSComparisonResult)NSOrderedDescending;
    }
    
    if ([obj1 integerValue] < [obj2 integerValue]) {
        return (NSComparisonResult)NSOrderedAscending;
    }
    return (NSComparisonResult)NSOrderedSame;
};
-(void)textViewDidChange:(UITextView *)textView{

//    NSArray *arr = @[@1,@2,@3,@4,@5,@6,@7,@8,@9,@10];
//    for (NSNumber *m in arr) {
//        LxDBAnyVar(m);
//    }
//    [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//        LxDBAnyVar(idx);
//        LxDBAnyVar(obj);
//    }];
    
    
    // 1.
    NSArray *sortArray = [[NSArray alloc] initWithObjects:@"1",@"3",@"4",@"71",@"8",@"2",@"6",@"5",@"13",@"15",@"12",@"20",@"28",@"",nil];
    NSArray *temp = [sortArray sortedArrayUsingFunction:customSort context:nil];
    for (NSString *str in temp) {
        LxDBAnyVar(str);
    }
    
    //2.
    NSArray *temp1 = [sortArray sortedArrayUsingComparator:cmptr];
    for (NSString *str in temp1) {
        LxDBAnyVar(str);
    }
    
//    NSMutableArray *p = [[NSMutableArray alloc] initWithObjects:@"S1",@"S14",@"S3",@"S4",@"S12",@"S6",@"S7",@"S8",@"S9",@"S10",@"S11",@"S5",@"S13",@"S2",nil];
//    NSArray*sorte = [p sortedArrayUsingComparator:^NSComparisonResult(BookListModel *obj1,BookListModel *obj2) {
//        return [obj1.tableName compare:obj2.tableName options:NSNumericSearch];
//    }];
}


@end
